<template>
	<view>
		<view>
			<!-- heaad -->
			<view class="head-box">
				<image src="../../static/image/page/jf-bg.png" class="jf-bg"></image>
				<view class="head-con">
					<view class="jf-title">当前积分</view>
					<view class="jf-num">{{integral.total}}</view>
				</view>
			</view>
			<!-- 积分信息 -->
			<view class="jf-info flex-center">
				<view class="jf-item flex-center">
					<text class="jf-item-title">积分获取</text>
					<text class="jf-item-num">+{{integral.income}}</text>
				</view>
				<view class="jf-line"></view>
				<view class="jf-item flex-center">
					<text class="jf-item-title">积分支出</text>
					<text class="jf-item-num">-{{integral.disburse}}</text>
				</view>
			</view>
			<!-- 积分明细 -->
			<view>
				<view class="flex-align">
					<view @click="changType" data-type="-1" class="jf-waper"><text
							:class="['jf-waper-title', {'active':type=='-1'}]">全部</text></view>
					<view @click="changType" data-type="1" class="jf-waper"><text
							:class="['jf-waper-title', {'active':type==1}]">收入</text></view>
					<view @click="changType" data-type="0" class="jf-waper"><text
							:class="['jf-waper-title', {'active':type==0}]">支出</text></view>
				</view>
				<view class="fj-list">
					<view class="fj-mx-item flex-space" v-for="(item,index) in list" :key="index">
						<view>
							<view class="item-title">{{item.description}}</view>
							<view class="time">{{item.createTime}}</view>
						</view>
						<text class="item-num">{{item.type?'+':'-'}}{{item.total+'.00'}}</text>
					</view>
				</view>
				<!-- 上拉触底无数据 -->
				<no-data v-if="isComplete"></no-data>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				integral: 0, //积分
				type: '-1', //类型 全部就不传  1是收入  0是支出
				formData: {
					eid: '', //用户id
					pageNo: 1,
					type: '',
				},
				isLoading: false,
				isComplete: false,
				list: [], //商品列表
			}
		},
		onLoad(options) {
			this.formData.eid = options.eid;
			this.integralSummary();
			this.getIntegralRecord();
		},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {
			!this.isLoading && !this.isComplete && this.getIntegralRecord();
		},

		methods: {
			//获取积分明细列表
			getIntegralRecord() {
				this.isLoading = true;
				this.$api.integralRecord(this.formData).then(res => {
					let data = res.data.data.records;

					this.isLoading = false;
					this.isComplete = !data.length;
					this.list = this.list.concat(data);
					this.formData.pageNo = ++this.formData.pageNo;
				})
			},
			//切换类型
			changType(e) {
				let type = e.currentTarget.dataset.type;
				this.type = type;
				this.formData.type = type == -1 ? '' : type;
				this.formData.pageNo = 1;
				this.list = [];
				this.getIntegralRecord();
			},
			//查询积分
			integralSummary() {
				this.$api.integralSummary().then(res => {

					this.integral = res.data.data;
				})
			},
		},

	};
</script>

<style scoped>
	.head-box {
		position: relative;
		width: 100%;
		height: 460rpx;

	}

	.jf-bg {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		width: 100%;
		height: 100%;
	}

	.head-con {
		width: 100%;
		position: relative;
		z-index: 2;
		text-align: center;
		padding-top: 50rpx;
	}

	.jf-title {
		font-size: 28rpx;
		color: #FFFFFF;
		margin-bottom: 38rpx;
	}

	.jf-num {
		font-size: 80rpx;
		font-weight: bold;
		color: #FFFFFF;
	}

	.jf-info {
		width: 691rpx;
		height: 130rpx;
		background: #FFFFFF;
		box-shadow: 0px 0px 40rpx 0px rgba(0, 0, 0, 0.06);
		border-radius: 65rpx;
		margin: -105rpx auto 0;
		position: relative;
		z-index: 9;
		margin-bottom: 47rpx;
	}

	.jf-item {
		flex: 1;
		flex-direction: column;
	}

	.jf-item-title {
		font-size: 28rpx;
		color: #333333;
		line-height: 40rpx;
	}

	.jf-item-num {
		font-size: 36rpx;
		font-weight: bold;
		color: #FC4073;
		line-height: 56rpx;
	}

	.jf-line {
		width: 1rpx;
		height: 70rpx;
		border: 1rpx solid #CCCCCC;
	}

	.jf-waper {
		flex: 1;
		text-align: center;


	}

	.jf-waper-title {
		font-size: 30rpx;
		color: #999999;
		display: inline-block;
		padding-bottom: 25rpx;
	}

	.active {
		color: #333333;
		border-bottom: 6rpx solid #585CF7;

	}

	.fj-list {
		padding: 0 30rpx;
		margin-top: 30rpx;
	}

	.fj-mx-item {
		height: 150rpx;
		width: 100%;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.item-num {
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
	}

	.item-title {
		font-size: 32rpx;
		color: #333333;
		margin-bottom: 28rpx;
	}

	.time {
		font-size: 24rpx;
		color: #999999;
	}
</style>
